﻿namespace Core
{
    public class UICloseButton : UIButton
    {
        private Window m_window;
        private UIWidget m_widget;

        public void Set(Window window) => m_window = window;
        public void Set(UIWidget widget) => m_widget = widget;

        public override void Dispose()
        {
            if (IsDisposed) return;
            base.Dispose();

            m_window = null;
            m_widget = null;
        }

        protected override void OnButtonClickHandler()
        {
            base.OnButtonClickHandler();

            m_widget?.SetActive(false);

            if (m_window != null)
            {
                G.UI.Close(m_window);
            }
        }
    }
}
